package com.javathread.aqs;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

import com.javathread.thread01.SleepTools;

public class TrinityLockTest {

	final static Lock lock = new TrinityLock();
	private static final class DoWorker extends Thread {
		
		private Condition condition = lock.newCondition();
		
		@Override
		public void run() {
			for(;;) {
				lock.lock();
				try {
					SleepTools.second(1);
					System.out.println("sub:"+Thread.currentThread().getName());
					SleepTools.second(1);
				} finally {
					lock.unlock();
				}
				SleepTools.second(2);
			}
		}
		
	} 	
	
	public static void main(String[] args) {
				//启动10个子线程
				for (int i =0; i < 10; i++) {
					DoWorker w = new DoWorker();
					w.setDaemon(true);
					w.start();
				}
				//主线程每隔1秒换行
				for (int i =0; i < 600 ; i++) {
					SleepTools.second(1);
					System.out.println("main*");
				}
				
				
	}
}
